#coding:utf-8
from . import main
from flask import render_template,session
from .. import model,db


@main.route('/h5')
def h5():
    print session.get('state')
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    return render_template('baes.html',state = session.get('state'),name = session.get('name'),id = id)

@main.route('/course/<num>')
def course(num):
    kinds =  db.session.query(model.Kinds).all()
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    kind = db.session.query(model.Kinds).filter(model.Kinds.id == num).first()
    course = kind.couses



    return render_template('course.html',kinds = kinds,kind = kind,id = id,course = course,state = session.get('state'),name = session.get('name'))


@main.route('/videos/<mun>')
def videos(mun):
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    course = db.session.query(model.Courses).filter(model.Courses.id == mun).first()
    videos = course.videos
    return render_template('videos.html',state = session.get('state'),name = session.get('name'),videos = videos,id = id,mun = mun)


@main.route('/teachers')
def teacher():
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    teachers = db.session.query(model.Teachers).all()
    return render_template('teachers.html',teachers = teachers,id = id,state = session.get('state'),name = session.get('name'))


    
# 修改
@main.route('/update_cou/<id>')
def update_cou(id):

    course = db.session.query(model.Courses).filter(model.Courses.id == id).first()
    print course.title
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    return render_template('update_cou.html',state = session.get('state'),name = session.get('name'),course = course,id = id)

@main.route('/update_vid/<id>')
def update_vid(id):
    video = db.session.query(model.Videos).filter(model.Videos.id == id).first()
    teacher = db.session.query(model.Teachers).filter(model.Teachers.id == video.t_id).first()
    # print teacher.name
    teachers = db.session.query(model.Teachers).all()
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    return render_template('update_vid.html',state = session.get('state'),name = session.get('name'),teachers = teachers,teacher = teacher,video = video,id = id)

@main.route('/update_teacher/<id>')
def update_teacher(id):
    teacher = db.session.query(model.Teachers).filter(model.Teachers.id == id).first()
    return render_template('update_teacher.html',state = session.get('state'),name = session.get('name'),teacher = teacher)


# 登录

@main.route('/login')
def login():
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    return render_template('login.html',state = session.get('state'),name = session.get('name'),id = id)


# 注册

@main.route('/register')
def register():
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    return render_template('register.html',state = session.get('state'),name = session.get('name'),id = id)


# 渲染添加course页面
@main.route('/add/course/<id>')
def add_cou(id):
    return render_template('addcourse.html',state = session.get('state'),name = session.get('name'),id=id)

# 渲染添加video页面
@main.route('/add/video/<num>')
def add_vid(num):
    teachers = db.session.query(model.Teachers).all()
    teacher = db.session.query(model.Teachers).first()
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    return render_template('addvideo.html',state = session.get('state'),name = session.get('name'),id=id,teachers = teachers,teacher = teacher,num = num)

# 渲染添加teacher页面
@main.route('/add/teacher')
def add_teacher():
    kind_1 = db.session.query(model.Kinds).first()
    id = kind_1.id
    return render_template('addteacher.html',state = session.get('state'),name = session.get('name'),id = id)
